package itheima.com.mythreadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolDemo6 {
    public static void main(String[] args) {
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                1,
                2,
                1,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),//队列中能排队的线程个数
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy());//抛弃等待最久的任务，将最后的任务添加进来（即最新的任务）
        for (int i = 1; i <= 10; i++) {
            int y = i;
            pool.submit(()->{
                System.out.println(Thread.currentThread().getName()+"---"+y);
            });
        }
        pool.shutdown();
    }
}
